home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Warrior cdev stub Folder / cdev stub.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  2KB  |  67 lines

  1. /*
  2.  
  3.     cdev code stub for MetroWerks CodeWarrior
  4.     by Joe Zobkiw (aflzobkiw@aol.com)
  5.     
  6.     MetroWerks CodeWarrior is a great little compiler/environment.
  7.     
  8.     Unfortunately a bug exists in the current version that doesn't allow you
  9.     to set the ID of a code-bearing resource to a negative number. This
  10.     makes it very difficult to work on a cdev (control panel device) using
  11.     CodeWarrior. Until now...
  12.     
  13.     Compile the following code "stub" in CodeWarrior, manually set it's ID to 
  14.     -4064, then paste it into your control panels resource file. You can now use
  15.     CodeWarrior to work on your real control panel code resource which you will
  16.     now give ID 4064 (instead of -4064.) When the Finder launches your control
  17.     panel, it will call the stub code in -4064 which will load and "call through"
  18.     to your _real_ code in 4064. Voila!
  19.     
  20.     Finder ---> -4064 stub ---> 4064 (your code)
  21.     
  22.     If you like, you can leave this stub in place forever, it will work fine.
  23.     I would suggest using it until the bug in MetroWerks is fixed, simply to
  24.     save you time. Enjoy and please let me know if there are any problems 
  25.     that you encounter. I've tested this on numerous cdevs and it seems to work 
  26.     fine.
  27.     
  28.     Questions, comments, etc. welcome.
  29.     
  30. */
  31.  
  32. typedef pascal long (*cdevProc)(    short message, 
  33.                                     short item, 
  34.                                     short numItems, 
  35.                                     short CPanelID,
  36.                                     EventRecord    *theEvent, 
  37.                                     Handle cdevStorage, 
  38.                                     DialogPtr CPDialog);
  39.  
  40. pascal long main(    short message, 
  41.                     short item, 
  42.                     short numItems, 
  43.                     short CPanelID,
  44.                     EventRecord    *theEvent, 
  45.                     Handle cdevStorage, 
  46.                     DialogPtr CPDialog)
  47. {
  48.     long     returnValue = cdevMemErr;                /* initialize to the worst */
  49.     Handle     h = Get1Resource('cdev', 4064);            /* load in our _real_ code */
  50.     
  51.     if (h != NULL) {
  52.         MoveHHi(h);                                    /* move it high */
  53.         HLock(h);                                    /* lock it down */
  54.         returnValue = ((cdevProc)(*h))(    message,     /* call it */
  55.                                         item, 
  56.                                         numItems, 
  57.                                         CPanelID, 
  58.                                         theEvent, 
  59.                                         cdevStorage, 
  60.                                         CPDialog);
  61.         HUnlock(h);                                    /* the unlock */
  62.         ReleaseResource(h);                            /* and the release */
  63.     }
  64.     
  65.     return returnValue;                                /* return whatever */
  66. }
  67.